const db = wx.cloud.database();
const app = getApp();

Page({

  /**
   * 页面的初始数据
   */
  data: {
    inputVal: "", // 搜索框值
    catList: [], //搜索渲染推荐数据
    act: 1,
    index1: 0,
    index12: 0,
    index: 0,
    index2: 0,
    index3: 0,
    index4: 0,
    index5: 0,
    province: ['请选择地市'],
    city: ['请选择县区'],
    dishi: ['请选择地市'],
    zhaolujiguan: ['请选择招录机关'],
    yongrendanwei: ['请选择用人单位'],
    zhiweimingcheng: ['请选择职位名称'],
    zhiweidaima: ['请选择职位代码'],
    phone: 0,
    theList: ''
  },
  onLoad: function (options) {
    var _ = this;
    var phone = wx.getStorageSync('fscxphone')
    console.log(phone)
    if(phone){
      _.setData({
        phone:true
      })
    }
    console.log(options)
    _.setData({
      area:options.area,
      uid:options.agent,
      page:options.page
    })
    var phone = wx.getStorageSync('phone')
    if(phone){
      _.setData({
        phone:!0
      })
    }
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=45488&callback=?', //接收url
      data: {
        level: '1',
        dishi: ''
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        var list = [];
        list.push('请选择地市')
        for (var i in theJson.lists) { //循环写入下来框

          list.push(theJson.lists[i].dishi)
        }
        _.setData({
          dishi: list
        });
      }
    })

    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=43761&callback=?', //接收url
      data: {
        level: '1',
        province: ''
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        var list = [];
        list.push('请选择地市')
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].province)
        }
        _.setData({
          province: list
        });
      }
    })
  },
  bindPicker1Change: function (e) {
    let num = e.detail.value;
    let _ = this;
    console.log('province发送选择改变，携带值为', _.data.province[num]);
    this.setData({
      index1: e.detail.value
    })
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=43761&callback=?', //接收url
      data: {
        level: '2',
        grfiled: 'province',
        grtext: _.data.province[num]
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        var list = [];
        list.push('请选择县区')
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].city)
        }
        _.setData({
          city: list
        });
      }
    })
  },
  bindPicker1Change2: function (e) {
    let num2 = e.detail.value;
    let _ = this;
    console.log('city发送选择改变，携带值为', _.data.city[num2]);
    this.setData({
      index12: e.detail.value
    })
   
  },
  bindPickerChange: function (e) {
    let num = e.detail.value;
    let _ = this;
    console.log('dishi发送选择改变，携带值为', _.data.dishi[num]);
    this.setData({
      index: e.detail.value
    })
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=45488&callback=?', //接收url
      data: {
        level: '2',
        grfiled: 'dishi',
        grtext: _.data.dishi[num]
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        var list = [];
        list.push('请选择招录机关')
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].zhaolujiguan)
        }
        _.setData({
          zhaolujiguan: list
        });
      }
    })
  },
  bindPickerChange2: function (e) {
    let num2 = e.detail.value;
    let _ = this;
    console.log('zhaolujiguan发送选择改变，携带值为', _.data.zhaolujiguan[num2]);
    this.setData({
      index2: e.detail.value
    })
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=45488&callback=?', //接收url
      data: {
        level: '3',
        grfiled: 'zhaolujiguan',
        grtext: _.data.zhaolujiguan[num2],
        onefiled: 'dishi',
        onetext: _.data.dishi[this.data.index]
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson)
        var list = [];
        list.push('请选择用人单位')
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].yongrendanwei)

        }
        _.setData({
          yongrendanwei: list
        });
      }
    })
  },
  bindPickerChange3: function (e) {
    let num3 = e.detail.value;
    let _ = this;
    console.log('yongrendanwei发送选择改变，携带值为', _.data.yongrendanwei[num3]);
    this.setData({
      index3: e.detail.value
    })
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=45488&callback=?', //接收url
      data: {
        level: '4',
        grfiled: 'yongrendanwei',
        grtext: _.data.yongrendanwei[num3],
        onefiled: 'dishi',
        onetext: _.data.dishi[this.data.index],
        twofiled: 'zhaolujiguan',
        twotext: _.data.zhaolujiguan[this.data.index2],
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson.lists)
        var list = [];
        list.push('请选择职位名称')
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].zhiweimingcheng)
        }
        _.setData({
          zhiweimingcheng: list
        });
      }
    })
  },
  bindPickerChange4: function (e) {
    let num4 = e.detail.value;
    let _ = this;
    console.log('zhiweimingcheng发送选择改变，携带值为', _.data.zhiweimingcheng[num4]);
    this.setData({
      index4: e.detail.value
    })
    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlevel?actid=45488&callback=?', //接收url
      data: {
        level: '5',
        grfiled: 'zhiweimingcheng',
        grtext: _.data.zhiweimingcheng[num4],
        onefiled: 'dishi',
        onetext: _.data.dishi[this.data.index],
        twofiled: 'zhaolujiguan',
        twotext: _.data.zhaolujiguan[this.data.index2],
        threefiled: 'yongrendanwei',
        threetext: _.data.yongrendanwei[this.data.index3],
      }, //接收参数
      success(res) {
        console.log(res)
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson)
        console.log(theJson.lists)
        var list = [];
        list.push('请选择职位代码')
        for (var i in theJson.lists) { //循环写入下来框
          list.push(theJson.lists[i].zhiweidaima)
        }
        _.setData({
          zhiweidaima: list
        });
      }
    })

  },
  bindPickerChange5: function (e) {
    let num5 = e.detail.value;
    let _ = this;
    console.log('zhiweidaima', _.data.zhiweidaima[num5]);
    this.setData({
      index5: e.detail.value
    })


  },


  // 键盘抬起事件
  inputTyping: function (e) {
    console.log("input-----", e)
    var value = e.detail.value
    var _ = this;
    var zys = _.data.zys
    if (value == '') {
      _.setData({
        viewShowed: false,
      });
    } else {
      //“这里需要特别注意，不然在选中下拉框值的时候，下拉框又出现”
      if (e.detail.cursor) { //e.detail.cursor表示input值当前焦点所在的位置
        var arr = [];
        for (var i = 0; i < zys.length; i++) {
          if (zys[i].indexOf(value) >= 0) {
            arr.push(zys[i]);
          }
        }
        console.log(arr)
        _.setData({
          viewShowed: true,
          carList: arr
        });
      }
    }
  },
  // 获取选中推荐列表中的值
  name: function (res) {

    var index = res.currentTarget.dataset.index
    var _ = this;
    console.log(_.data.carList[index]);

    wx.request({ //发送请求
      url: 'https://zg99.offcn.com/index/chaxun/getlist?actid=26067&callback=?', //接收url
      data: {
        phone: '15205451183',
        zhuanye: _.data.carList[index],
        limits: 500
      }, //接收参数
      success(res) {
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        }
        console.log(theJson.lists[0].dalei)
        _.setData({
          theDalei: theJson.lists[0].dalei
        })
      }
    })
    _.setData({
      inputVal: _.data.carList[index],
      viewShowed: false,
    })
  },
  zkzInput: function (e) {
    this.setData({
      zkz: e.detail.value
    })
    console.log(this.data.zkz)
  },

  ontap: function (e) {
    var _ = this;
    console.log(e.currentTarget.dataset.act)
    var a = parseInt(e.currentTarget.dataset.act)
    this.setData({
      act: a
    })
  },

  tijiao: function (res) {
    var _ = this;
    var dishi = _.data.dishi[_.data.index];
    var zhaolujiguan = _.data.zhaolujiguan[_.data.index2];
    var yongrendanwei = _.data.yongrendanwei[_.data.index3];
    var zhiweimingcheng = _.data.zhiweimingcheng[_.data.index4];
    var zhiweidaima = _.data.zhiweidaima[_.data.index5];
    var zkz = _.data.zkz;
    wx.request({ //发送请求
      url: "https://zg99.offcn.com/index/chaxun/updateuser/?actid=45488&callback=?",
      data: {
        phone: wx.getStorageSync('fscxphone'),
        zkz: zkz
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        };
        console.log(theJson)
      }
    })
    wx.request({ //发送请求
      url: "https://zg99.offcn.com/index/chaxun/getlist/?actid=45488&callback=?",
      data: {
        dishi: dishi,
        zhaolujiguan: zhaolujiguan,
        yongrendanwei: yongrendanwei,
        zhiweimingcheng: zhiweimingcheng,
        limits: '100'
      }, //接收参数
      success(res) { //返回
        
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        };
        console.log(theJson.lists[0].gangweipipei)
        if (theJson.status == '2') {
          console.log('暂无数据！')
          wx.showToast({
            title: '暂无数据',
            icon: 'none',
            duration: 2000
          })
        } else {
         
          wx.request({ //发送请求
            url: "https://zg99.offcn.com/index/chaxun/getlist/?actid=45488&callback=?",
            data: {
              gangweipipei: theJson.lists[0].gangweipipei,
              tabnum: 2,
              limits: '100'
            }, //接收参数
            success(res) { //返回
              var jsonStr = res.data;
              jsonStr = jsonStr.replace("(", "");
              jsonStr = jsonStr.replace(")", "");
              if (typeof jsonStr != 'object') {
                jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
                var theJson = JSON.parse(jsonStr);
              };
              console.log(theJson)
              if (theJson.status == '2') {
                console.log('暂无数据！')
                wx.showToast({
                  title: '暂无数据',
                  icon: 'none',
                  duration: 2000
                })
              } else {
                wx.setStorageSync('theList',  theJson.lists)
                wx.navigateTo({
                  url: '../result/result?List=0',
                })
            
              }
      
              console.log(_.data.theList)
            }
          })
      
        }

      }
    })
  },
  tijiao1: function (res) {
    var _ = this;
    var dishi1 = _.data.province[_.data.index1];
    var xianqu1 = _.data.city[_.data.index12];
    var zkz = _.data.zkz;
    wx.request({ //发送请求
      url: "https://zg99.offcn.com/index/chaxun/updateuser/?actid=45488&callback=?",
      data: {
        phone: wx.getStorageSync('fscxphone'),
        zkz: zkz
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        };
        console.log(theJson)
      }
    })
    wx.request({ //发送请求
      url: "https://zg99.offcn.com/index/chaxun/getlist/?actid=45488&callback=?",
      data: {
        dishiyi: dishi1,
        xianquyi: xianqu1,
        tabnum: 2,
        limits: '100'
      }, //接收参数
      success(res) { //返回
        var jsonStr = res.data;
        jsonStr = jsonStr.replace("(", "");
        jsonStr = jsonStr.replace(")", "");
        if (typeof jsonStr != 'object') {
          jsonStr = jsonStr.replace(/\ufeff/g, ""); //字符串转化JSON对象
          var theJson = JSON.parse(jsonStr);
        };
        console.log(theJson)
        if (theJson.status == '2') {
          console.log('暂无数据！')
          wx.showToast({
            title: '暂无数据',
            icon: 'none',
            duration: 2000
          })
        } else {
          wx.setStorageSync('theList1',  theJson.lists[0])
          wx.navigateTo({
            url: '../result/result?List=1',
          })
        }

        console.log(_.data.theList)
      }
    })
  },

  
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})